package com.example.sell_qq.dao;

import com.alibaba.fastjson.JSONObject;
import com.example.sell_qq.constant.ApiConstant;
import com.example.sell_qq.entity.AddressBook;
import com.example.sell_qq.util.HttpUtils;
import com.example.sell_qq.vo.ResponseVO;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 通讯录 dao 层
 */
public class AddressBookDao {

    /**
     * 保存所有通讯录
     * @param addressBooks 通讯录
     * @throws IOException 保存失败
     */
    public void saveAllAddressBook(List<AddressBook> addressBooks) throws IOException {
        if (addressBooks == null) {
            return;
        }
        String saveAddressBookAPI = ApiConstant.EXPORT_API + "/address_book/many";
        List<JSONObject> addressBookJson = new ArrayList<>();
        for (AddressBook addressBook : addressBooks) {
            addressBookJson.add((JSONObject) JSONObject.toJSON(addressBook));
        }

        String response = HttpUtils.httpJsonPost(saveAddressBookAPI, addressBookJson.toString());

        HttpUtils.resolveResponse(response);
    }



}
